package com.dhb.pattern.adapter.ext;

import com.dhb.pattern.adapter.ResultMsg;
import com.dhb.pattern.adapter.SiginService;

/**
 * 功能描述：
 * 创建人：citymoon
 * 创建日期：2019/5/25
 */
public class PassportForThirdAdapter extends SiginService implements IPassportForThird {
    @Override
    public ResultMsg loginForQQ(String id) {
        return processLogin(id,LoginForQQAdapter.class);
    }

    @Override
    public ResultMsg loginForWechat(String id) {

        return processLogin(id, LoginForWechatAdapter.class);
    }

    private ResultMsg processLogin(String id, Class<? extends LoginAdapter> clazz) {
        try {
            LoginAdapter adapter = clazz.newInstance();
            if(adapter.support(adapter)){
                return adapter.login(id,adapter);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
